﻿var parentUnitTree;

function loadTree() {
    var setting = {
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: null
            }
        },
        view: {
            showLine: true, //是否显示节点间的连线
            showIcon: true
        },
        check: {
            autoCheckTrigger: true,
            chkboxType: { "Y": "ps", "N": "ps" },
            chkStyle: "radio",
            enable: true,
            radioType: "all",//"level"
        }
    };
    var treeNodes = $.parseJSON($("#nodesJson").val());

    parentUnitTree = $.fn.zTree.init($("#tree"), setting, treeNodes);
    $("#nodesJson").remove();
}

$(document).ready(function () {
    $("#confirmParentBtn").click(function () {
        var selectedNodes = parentUnitTree.getCheckedNodes();
        //alert("haha");
        //alert(selectedNodes[0].id.substr(0, 4));
        if (selectedNodes.length > 0) {
            var id = selectedNodes[0].id;
            var name = selectedNodes[0].name;
            window.top.art.dialog.get('operationmanagecontractcreate').iframe.contentDocument.all["ParentUnitName"].value = name;
            window.top.art.dialog.get('operationmanagecontractcreate').iframe.contentDocument.all["ParentUnitID"].value = id;

            window.top.art.dialog.get('operationmanageusercreatepickparent').close();
        }
        else {
            artDialogAlert("请先选择一个单位");
        }
    });

    $("#cancelParentBtn").click(function () {
        window.top.art.dialog.get('operationmanageusercreatepickclient').close();
    });
});